package com.dgut.admin.controller;

import com.dgut.admin.param.LoginParam;
import com.dgut.admin.param.PasswordParam;
import com.dgut.admin.service.AdminUserService;
import com.dgut.common.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author IT00ZYQ
 * @date 2022/1/8 8:47
 **/
@RestController
@RequestMapping("/api/admin/user")
public class AdminUserController {

    private final AdminUserService adminUserService;

    public AdminUserController(AdminUserService adminUserService) {
        this.adminUserService = adminUserService;
    }

    /**
     * 登录
     * @param param 账号信息
     * @return 登录信息
     */
    @PostMapping("/login")
    public R login(@RequestBody @Valid LoginParam param) {
        return R.ok().data(adminUserService.login(param));
    }

    /**
     * 修改密码
     * @param param 账号信息
     * @param token 登录令牌
     * @return void
     */
    @PutMapping("/password")
    public R updatePassword(@RequestBody @Valid PasswordParam param,
                            @RequestHeader("token") String token) {
        adminUserService.updatePassword(param, token);
        return R.ok();
    }


}
